Skip to contentSkip to conversation

Change in openvpn[master]: event/multi: add event_arg object to make event handling more generic

Openvpn-devel Superseded its_Giaan (Code Review) 3 participants 23 messages Sep 23, 2024 – Oct 23, 2024 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): gerrit.1727098847000.Icd7f6a2ad350cdc2312b3e80fa0dbdd7e4311d2e@...2715...

#1 lore raw

Attention is currently required from: flichtenheld, ordex, plaisthos.

Hello plaisthos, flichtenheld,

I'd like you to do a code review.
Please visit

    http://gerrit.openvpn.net/c/openvpn/+/757?usp=email

to review the following change.

Change subject: event/multi: add event_arg object to make event handling more generic
......................................................................

event/multi: add event_arg object to make event handling more generic

In order to prepare the event handling code to deal with multiple listening sockets, we have to make sure that it is possible to distinguish which of these sockets have been pocked by an incoming connection request.

To achieve that, this patch changes the object being passed as event handler argument, from a "partly integer evaluated variable" to a full struct with a proper type attribute.

This struct will allow the code to carry around the particular listening socket where the connection is being established.

This change affects the TCP server code path only as UDP servers use only one socket to handle all clients i/o.

Change-Id Icd7f6a2ad350cdc2312b3e80fa0dbdd7e4311d2e

---
M src/openvpn/event.h
M src/openvpn/mtcp.c
M src/openvpn/multi.c
M src/openvpn/multi.h
M src/openvpn/socket.c
M src/openvpn/socket.h

6 files changed, 59 insertions(+), 15 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/57/757/1

src/openvpn/event.h +14 -0
index 856551a..844ea7b 100644
@@ -126,6 +126,20 @@
     struct event_set_functions func;
 };
 
+typedef enum {
+    EVENT_ARG_MULTI_INSTANCE = 0,
+    EVENT_ARG_LINK_SOCKET,
+} event_arg_t;
+
+/* generic event argument object to pass to event_ctl() */
+struct event_arg
+{
+    event_arg_t type;
+    union {
+        struct multi_instance *mi; /* if type = EVENT_ARG_MULTI_INSTANCE */
+    } u;
+};
+
 /*
  * maxevents on input:  desired max number of event_t descriptors
  *                      simultaneously set with event_ctl
src/openvpn/mtcp.c +37 -15

80 lines not on this page · raw message

src/openvpn/multi.c +3 -0
index 0509911..45b3cfa 100644
@@ -823,6 +823,9 @@
         goto err;
     }
 
+    mi->ev_arg.type = EVENT_ARG_MULTI_INSTANCE;
+    mi->ev_arg.u.mi = mi;
+
     perf_pop();
     gc_free(&gc);
     return mi;
src/openvpn/multi.h +1 -0
index 7167639..e403989 100644
@@ -102,6 +102,7 @@
     struct schedule_entry se;  /* this must be the first element of the structure,
                                 * We cast between this and schedule_entry so the
                                 * beginning of the struct must be identical */
+    struct event_arg ev_arg;
     struct gc_arena gc;
     bool halt;
     int refcount;
src/openvpn/socket.c +2 -0
index 6c790a0..924e30c 100644
@@ -1827,6 +1827,8 @@
     ALLOC_OBJ_CLEAR(sock, struct link_socket);
     sock->sd = SOCKET_UNDEFINED;
     sock->ctrl_sd = SOCKET_UNDEFINED;
+    sock->ev_arg.type = EVENT_ARG_LINK_SOCKET;
+
     return sock;
 }
 
src/openvpn/socket.h +2 -0
index bbdabfb..6857202 100644
@@ -166,6 +166,8 @@
 {
     struct link_socket_info info;
 
+    struct event_arg ev_arg;
+
     socket_descriptor_t sd;
     socket_descriptor_t ctrl_sd; /* only used for UDP over Socks */
 

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/757?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Icd7f6a2ad350cdc2312b3e80fa0dbdd7e4311d2e
Gerrit-Change-Number: 757
Gerrit-PatchSet: 1
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: ordex <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-MessageType: newchange

#2 lore raw
In reply to a message not in the archive

Attention is currently required from: its_Giaan, ordex, plaisthos.

flichtenheld has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/757?usp=email )

Change subject: event/multi: add event_arg object to make event handling more generic
......................................................................

Patch Set 1: Code-Review-1

(6 comments)

Commit Message:

http://gerrit.openvpn.net/c/openvpn/+/757/comment/d285fad6_adb4db9c :
PS1, Line 11: distinguish which of these sockets have been pocked by an incoming poked?

http://gerrit.openvpn.net/c/openvpn/+/757/comment/8fd531fb_1f14a455 :
PS1, Line 15: event handler argument, from a "partly integer evaluated variable" "integer-evaluated" would be easier to parse I think.

http://gerrit.openvpn.net/c/openvpn/+/757/comment/e6c649bc_aca2f81f :
PS1, Line 22: use only one socket to handle all clients i/o. Sounds clunky, "I/O of all clients" maybe? Or just "all clients."

Patchset:

PS1:
Documentation review.
Please also note the "Uncrustify" failure.

File src/openvpn/multi.h:

http://gerrit.openvpn.net/c/openvpn/+/757/comment/f0c63fc8_4797f681 :
PS1, Line 105: struct event_arg ev_arg;
Please add documentation

What is the advantage of storing this in the mi itself? Memory handling?

File src/openvpn/socket.h:

http://gerrit.openvpn.net/c/openvpn/+/757/comment/91cb60e0_7934e9e5 :
PS1, Line 169: struct event_arg ev_arg;
Please add documentation

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/757?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Icd7f6a2ad350cdc2312b3e80fa0dbdd7e4311d2e
Gerrit-Change-Number: 757
Gerrit-PatchSet: 1
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: ordex <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-Comment-Date: Wed, 25 Sep 2024 09:51:33 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment

#3 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, its_Giaan, plaisthos.

ordex has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/757?usp=email )

Change subject: event/multi: add event_arg object to make event handling more generic
......................................................................

Patch Set 1:

(5 comments)

Commit Message:

http://gerrit.openvpn.net/c/openvpn/+/757/comment/aa46d7bd_e7e189df :
PS1, Line 11: distinguish which of these sockets have been pocked by an incoming

Quoted 1 line

poked?

Acknowledged

http://gerrit.openvpn.net/c/openvpn/+/757/comment/adc64174_bd2c6985 :
PS1, Line 15: event handler argument, from a "partly integer evaluated variable"

Quoted 1 line

"integer-evaluated" would be easier to parse I think.

Acknowledged

http://gerrit.openvpn.net/c/openvpn/+/757/comment/7946288e_fc23bcb7 :
PS1, Line 22: use only one socket to handle all clients i/o.

Quoted 1 line

Sounds clunky, "I/O of all clients" maybe? Or just "all clients. […]

'all clients' sounds good

File src/openvpn/multi.h:

http://gerrit.openvpn.net/c/openvpn/+/757/comment/a9e5c953_3086edb7 :
PS1, Line 105: struct event_arg ev_arg;

Quoted 1 line

Please add documentation […]

With the current approach we pass &mi as data to the event engine, because if data is an address we know for sure that it must be a mi. Now we want to put ourselves in the position to pass either a multi_instance or a link_socket object.
For this reason we can't simply pass their address as we would not have a way to understand what object that is.
Therefore the idea is to use a new struct (ev_arg) which internally will give me the pointer of the mi or ls, depending on the event type. Since we need this new struct to live somewhere, it was easier to locate it within the same struct that it points to (hence link_socket and multi_instance).

To some extends, you may take it as a "event base class", which is then interpreted as mi or ls.

Does it help understanding what is going on?

File src/openvpn/socket.h:

http://gerrit.openvpn.net/c/openvpn/+/757/comment/b8214964_f33cc340 :
PS1, Line 169: struct event_arg ev_arg;

Quoted 1 line

Please add documentation

explained in previous reply.

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/757?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Icd7f6a2ad350cdc2312b3e80fa0dbdd7e4311d2e
Gerrit-Change-Number: 757
Gerrit-PatchSet: 1
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: ordex <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Wed, 25 Sep 2024 11:47:12 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: flichtenheld <[email protected]...>
Gerrit-MessageType: comment

#4 lore raw
In reply to a message not in the archive

Attention is currently required from: its_Giaan, ordex, plaisthos.

flichtenheld has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/757?usp=email )

Change subject: event/multi: add event_arg object to make event handling more generic
......................................................................

Patch Set 1:

(1 comment)

File src/openvpn/multi.h:

http://gerrit.openvpn.net/c/openvpn/+/757/comment/3b5bb7d4_ed938931 :
PS1, Line 105: struct event_arg ev_arg;

Quoted 1 line

With the current approach we pass &mi as data to the event engine, because if data is an address we […]

Thanks for the explanation. Maybe we can add an abbreviated version of that as a comment here? How about "pointer to ourselves for purposes of passing it as event data"?

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/757?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Icd7f6a2ad350cdc2312b3e80fa0dbdd7e4311d2e
Gerrit-Change-Number: 757
Gerrit-PatchSet: 1
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: ordex <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-Comment-Date: Wed, 25 Sep 2024 11:53:07 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: flichtenheld <[email protected]...>
Comment-In-Reply-To: ordex <[email protected]...>
Gerrit-MessageType: comment

#5 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, its_Giaan, plaisthos.

Hello flichtenheld, ordex, plaisthos,

I'd like you to reexamine a change. Please visit

    http://gerrit.openvpn.net/c/openvpn/+/757?usp=email

to look at the new patch set (#2).

The following approvals got outdated and were removed:
Code-Review-1 by flichtenheld

Change subject: event/multi: add event_arg object to make event handling more generic
......................................................................

event/multi: add event_arg object to make event handling more generic

In order to prepare the event handling code to deal with multiple listening sockets, we have to make sure that it is possible to distinguish which of these sockets have been poked by an incoming connection request.

To achieve that, this patch changes the object being passed as event handler argument, from a "partly integer-evaluated variable" to a full struct with a proper type attribute.

This struct will allow the code to carry around the particular listening socket where the connection is being established.

This change affects the TCP server code path only as UDP servers use only one socket to handle all clients.

Change-Id Icd7f6a2ad350cdc2312b3e80fa0dbdd7e4311d2e

---
M src/openvpn/event.h
M src/openvpn/mtcp.c
M src/openvpn/multi.c
M src/openvpn/multi.h
M src/openvpn/socket.c
M src/openvpn/socket.h

6 files changed, 68 insertions(+), 15 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/57/757/2

src/openvpn/event.h +14 -0
index 856551a..844ea7b 100644
@@ -126,6 +126,20 @@
     struct event_set_functions func;
 };
 
+typedef enum {
+    EVENT_ARG_MULTI_INSTANCE = 0,
+    EVENT_ARG_LINK_SOCKET,
+} event_arg_t;
+
+/* generic event argument object to pass to event_ctl() */
+struct event_arg
+{
+    event_arg_t type;
+    union {
+        struct multi_instance *mi; /* if type = EVENT_ARG_MULTI_INSTANCE */
+    } u;
+};
+
 /*
  * maxevents on input:  desired max number of event_t descriptors
  *                      simultaneously set with event_ctl
src/openvpn/mtcp.c +38 -15

81 lines not on this page · raw message

src/openvpn/multi.c +3 -0
index 0509911..45b3cfa 100644
@@ -823,6 +823,9 @@
         goto err;
     }
 
+    mi->ev_arg.type = EVENT_ARG_MULTI_INSTANCE;
+    mi->ev_arg.u.mi = mi;
+
     perf_pop();
     gc_free(&gc);
     return mi;
src/openvpn/multi.h +6 -0
index 7167639..9e1b7bf 100644
@@ -102,6 +102,12 @@
     struct schedule_entry se;  /* this must be the first element of the structure,
                                 * We cast between this and schedule_entry so the
                                 * beginning of the struct must be identical */
+
+    struct event_arg ev_arg;   /* this struct will store a pointer to either mi or
+                                * link_socket, depending on the event type, to keep
+                                * it accessible it's placed within the same struct
+                                * it points to. */
+
     struct gc_arena gc;
     bool halt;
     int refcount;
src/openvpn/socket.c +2 -0
index 7b1e603..cf04090 100644
@@ -1830,6 +1830,8 @@
     ALLOC_OBJ_CLEAR(sock, struct link_socket);
     sock->sd = SOCKET_UNDEFINED;
     sock->ctrl_sd = SOCKET_UNDEFINED;
+    sock->ev_arg.type = EVENT_ARG_LINK_SOCKET;
+
     return sock;
 }
 
src/openvpn/socket.h +5 -0
index 2e583af..59e717c 100644
@@ -178,6 +178,11 @@
 {
     struct link_socket_info info;
 
+    struct event_arg ev_arg;   /* this struct will store a pointer to either mi or
+                                * link_socket, depending on the event type, to keep
+                                * it accessible it's placed within the same struct
+                                * it points to. */
+
     socket_descriptor_t sd;
     socket_descriptor_t ctrl_sd; /* only used for UDP over Socks */
 

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/757?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Icd7f6a2ad350cdc2312b3e80fa0dbdd7e4311d2e
Gerrit-Change-Number: 757
Gerrit-PatchSet: 2
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-CC: ordex <[email protected]...>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newpatchset

#6 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, ordex, plaisthos.

its_Giaan has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/757?usp=email )

Change subject: event/multi: add event_arg object to make event handling more generic
......................................................................

Patch Set 2:

(2 comments)

Commit Message:

http://gerrit.openvpn.net/c/openvpn/+/757/comment/eadf9bcc_81dbfe1d :
PS1, Line 22: use only one socket to handle all clients i/o.

Quoted 1 line

'all clients' sounds good

Done

File src/openvpn/multi.h:

http://gerrit.openvpn.net/c/openvpn/+/757/comment/2fce0b95_820412c6 :
PS1, Line 105: struct event_arg ev_arg;

Quoted 1 line

Thanks for the explanation. […]

Done

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/757?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Icd7f6a2ad350cdc2312b3e80fa0dbdd7e4311d2e
Gerrit-Change-Number: 757
Gerrit-PatchSet: 2
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-CC: ordex <[email protected]...>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-Comment-Date: Tue, 01 Oct 2024 15:30:50 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: flichtenheld <[email protected]...>
Comment-In-Reply-To: ordex <[email protected]...>
Gerrit-MessageType: comment

#7 lore raw
In reply to a message not in the archive

Attention is currently required from: its_Giaan, ordex, plaisthos.

flichtenheld has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/757?usp=email )

Change subject: event/multi: add event_arg object to make event handling more generic
......................................................................

Patch Set 2: Code-Review-1

(4 comments)

File src/openvpn/mtcp.c:

http://gerrit.openvpn.net/c/openvpn/+/757/comment/5bf1ba01_bbec3305 :
PS2, Line 758: MTCP_SOCKET
Shouldn't this "else if" part be removed? Or is there still some way left how this could be true? Doesn't look to me like it could,

File src/openvpn/multi.h:

http://gerrit.openvpn.net/c/openvpn/+/757/comment/ba0426ba_82f1a738 :
PS2, Line 106: struct event_arg ev_arg; /* this struct will store a pointer to either mi or
I think new comments should use doxygen formatting. See e.g. "time_t created" below.

File src/openvpn/socket.h:

http://gerrit.openvpn.net/c/openvpn/+/757/comment/74f701ee_1213a009 :
PS2, Line 181: struct
I think new comments should use doxygen formatting.

File src/openvpn/socket.h:

http://gerrit.openvpn.net/c/openvpn/+/757/comment/8f74e8f6_5f1dbc35 :
PS1, Line 169: struct event_arg ev_arg;

Quoted 1 line

explained in previous reply.

Done

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/757?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Icd7f6a2ad350cdc2312b3e80fa0dbdd7e4311d2e
Gerrit-Change-Number: 757
Gerrit-PatchSet: 2
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-CC: ordex <[email protected]...>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-Comment-Date: Wed, 02 Oct 2024 11:38:32 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Comment-In-Reply-To: flichtenheld <[email protected]...>
Comment-In-Reply-To: ordex <[email protected]...>
Gerrit-MessageType: comment

#8 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, its_Giaan, plaisthos.

ordex has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/757?usp=email )

Change subject: event/multi: add event_arg object to make event handling more generic
......................................................................

Patch Set 2:

(1 comment)

File src/openvpn/mtcp.c:

http://gerrit.openvpn.net/c/openvpn/+/757/comment/f6c97dcb_589dc379 :
PS2, Line 758: MTCP_SOCKET

Quoted 1 line

Shouldn't this "else if" part be removed? Or is there still some way left how this could be true? Do […]

Good catch. This indeed removed in a later patch, but it can already go away here (including the definition of MTCP_SOCKET)

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/757?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Icd7f6a2ad350cdc2312b3e80fa0dbdd7e4311d2e
Gerrit-Change-Number: 757
Gerrit-PatchSet: 2
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-CC: ordex <[email protected]...>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Fri, 04 Oct 2024 11:36:09 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: flichtenheld <[email protected]...>
Gerrit-MessageType: comment

#9 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, its_Giaan, ordex, plaisthos.

Hello flichtenheld, ordex, plaisthos,

I'd like you to reexamine a change. Please visit

    http://gerrit.openvpn.net/c/openvpn/+/757?usp=email

to look at the new patch set (#3).

The following approvals got outdated and were removed:
Code-Review-1 by flichtenheld

Change subject: event/multi: add event_arg object to make event handling more generic
......................................................................

event/multi: add event_arg object to make event handling more generic

In order to prepare the event handling code to deal with multiple listening sockets, we have to make sure that it is possible to distinguish which of these sockets have been poked by an incoming connection request.

To achieve that, this patch changes the object being passed as event handler argument, from a "partly integer-evaluated variable" to a full struct with a proper type attribute.

This struct will allow the code to carry around the particular listening socket where the connection is being established.

This change affects the TCP server code path only as UDP servers use only one socket to handle all clients.

Change-Id Icd7f6a2ad350cdc2312b3e80fa0dbdd7e4311d2e

---
M src/openvpn/event.h
M src/openvpn/mtcp.c
M src/openvpn/multi.c
M src/openvpn/multi.h
M src/openvpn/socket.c
M src/openvpn/socket.h

6 files changed, 68 insertions(+), 28 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/57/757/3

src/openvpn/event.h +14 -0
index 856551a..844ea7b 100644
@@ -126,6 +126,20 @@
     struct event_set_functions func;
 };
 
+typedef enum {
+    EVENT_ARG_MULTI_INSTANCE = 0,
+    EVENT_ARG_LINK_SOCKET,
+} event_arg_t;
+
+/* generic event argument object to pass to event_ctl() */
+struct event_arg
+{
+    event_arg_t type;
+    union {
+        struct multi_instance *mi; /* if type = EVENT_ARG_MULTI_INSTANCE */
+    } u;
+};
+
 /*
  * maxevents on input:  desired max number of event_t descriptors
  *                      simultaneously set with event_ctl
src/openvpn/mtcp.c +38 -28

106 lines not on this page · raw message

src/openvpn/multi.c +3 -0
index 0509911..45b3cfa 100644
@@ -823,6 +823,9 @@
         goto err;
     }
 
+    mi->ev_arg.type = EVENT_ARG_MULTI_INSTANCE;
+    mi->ev_arg.u.mi = mi;
+
     perf_pop();
     gc_free(&gc);
     return mi;
src/openvpn/multi.h +6 -0
index 7167639..7b78ddd 100644
@@ -102,6 +102,12 @@
     struct schedule_entry se;  /* this must be the first element of the structure,
                                 * We cast between this and schedule_entry so the
                                 * beginning of the struct must be identical */
+
+    struct event_arg ev_arg;   /** this struct will store a pointer to either mi or
+                                * link_socket, depending on the event type, to keep
+                                * it accessible it's placed within the same struct
+                                * it points to. */
+
     struct gc_arena gc;
     bool halt;
     int refcount;
src/openvpn/socket.c +2 -0
index 7b1e603..cf04090 100644
@@ -1830,6 +1830,8 @@
     ALLOC_OBJ_CLEAR(sock, struct link_socket);
     sock->sd = SOCKET_UNDEFINED;
     sock->ctrl_sd = SOCKET_UNDEFINED;
+    sock->ev_arg.type = EVENT_ARG_LINK_SOCKET;
+
     return sock;
 }
 
src/openvpn/socket.h +5 -0
index 2e583af..5ff31ea 100644
@@ -178,6 +178,11 @@
 {
     struct link_socket_info info;
 
+    struct event_arg ev_arg;   /** this struct will store a pointer to either mi or
+                                * link_socket, depending on the event type, to keep
+                                * it accessible it's placed within the same struct
+                                * it points to. */
+
     socket_descriptor_t sd;
     socket_descriptor_t ctrl_sd; /* only used for UDP over Socks */
 

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/757?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Icd7f6a2ad350cdc2312b3e80fa0dbdd7e4311d2e
Gerrit-Change-Number: 757
Gerrit-PatchSet: 3
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: ordex <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-MessageType: newpatchset

#10 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, ordex, plaisthos.

its_Giaan has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/757?usp=email )

Change subject: event/multi: add event_arg object to make event handling more generic
......................................................................

Patch Set 3:

(3 comments)

File src/openvpn/mtcp.c:

http://gerrit.openvpn.net/c/openvpn/+/757/comment/e7aac78d_dff6d54f :
PS2, Line 758: MTCP_SOCKET

Quoted 1 line

Good catch. […]

Done

File src/openvpn/multi.h:

http://gerrit.openvpn.net/c/openvpn/+/757/comment/c6c7c88f_56fb271e :
PS2, Line 106: struct event_arg ev_arg; /* this struct will store a pointer to either mi or

Quoted 1 line

I think new comments should use doxygen formatting. See e.g. "time_t created" below.

Done

File src/openvpn/socket.h:

http://gerrit.openvpn.net/c/openvpn/+/757/comment/7f68de79_70d1df94 :
PS2, Line 181: struct

Quoted 1 line

I think new comments should use doxygen formatting.

Done

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/757?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Icd7f6a2ad350cdc2312b3e80fa0dbdd7e4311d2e
Gerrit-Change-Number: 757
Gerrit-PatchSet: 3
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: ordex <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-Comment-Date: Wed, 09 Oct 2024 08:15:14 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: flichtenheld <[email protected]...>
Comment-In-Reply-To: ordex <[email protected]...>
Gerrit-MessageType: comment

#11 lore raw
In reply to a message not in the archive

Attention is currently required from: its_Giaan, ordex, plaisthos.

flichtenheld has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/757?usp=email )

Change subject: event/multi: add event_arg object to make event handling more generic
......................................................................

Patch Set 3: Code-Review-1

(3 comments)

File src/openvpn/mtcp.c:

http://gerrit.openvpn.net/c/openvpn/+/757/comment/ade8c2b8_33f9715f :
PS3, Line 694: *
any reason to define this before the if?

File src/openvpn/multi.h:

http://gerrit.openvpn.net/c/openvpn/+/757/comment/6dd1c266_a3590871 :
PS3, Line 106: this
Forgot "<" so this comment applies to gc

File src/openvpn/socket.h:

http://gerrit.openvpn.net/c/openvpn/+/757/comment/3c66faa3_fd3f993f :
PS3, Line 181: struct event_arg ev_arg; /** this struct will store a pointer to either mi or
Forgot "<" so this comment applies to sd

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/757?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Icd7f6a2ad350cdc2312b3e80fa0dbdd7e4311d2e
Gerrit-Change-Number: 757
Gerrit-PatchSet: 3
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: ordex <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-Comment-Date: Wed, 09 Oct 2024 16:41:24 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment

#12 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, its_Giaan, plaisthos.

Hello flichtenheld, ordex, plaisthos,

I'd like you to reexamine a change. Please visit

    http://gerrit.openvpn.net/c/openvpn/+/757?usp=email

to look at the new patch set (#4).

The following approvals got outdated and were removed:
Code-Review-1 by flichtenheld

Change subject: event/multi: add event_arg object to make event handling more generic
......................................................................

event/multi: add event_arg object to make event handling more generic

In order to prepare the event handling code to deal with multiple listening sockets, we have to make sure that it is possible to distinguish which of these sockets have been poked by an incoming connection request.

To achieve that, this patch changes the object being passed as event handler argument, from a "partly integer-evaluated variable" to a full struct with a proper type attribute.

This struct will allow the code to carry around the particular listening socket where the connection is being established.

This change affects the TCP server code path only as UDP servers use only one socket to handle all clients.

Change-Id Icd7f6a2ad350cdc2312b3e80fa0dbdd7e4311d2e

---
M src/openvpn/event.h
M src/openvpn/mtcp.c
M src/openvpn/multi.c
M src/openvpn/multi.h
M src/openvpn/socket.c
M src/openvpn/socket.h

6 files changed, 68 insertions(+), 28 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/57/757/4

src/openvpn/event.h +14 -0
index 856551a..844ea7b 100644
@@ -126,6 +126,20 @@
     struct event_set_functions func;
 };
 
+typedef enum {
+    EVENT_ARG_MULTI_INSTANCE = 0,
+    EVENT_ARG_LINK_SOCKET,
+} event_arg_t;
+
+/* generic event argument object to pass to event_ctl() */
+struct event_arg
+{
+    event_arg_t type;
+    union {
+        struct multi_instance *mi; /* if type = EVENT_ARG_MULTI_INSTANCE */
+    } u;
+};
+
 /*
  * maxevents on input:  desired max number of event_t descriptors
  *                      simultaneously set with event_ctl
src/openvpn/mtcp.c +38 -28

105 lines not on this page · raw message

src/openvpn/multi.c +3 -0
index 0509911..45b3cfa 100644
@@ -823,6 +823,9 @@
         goto err;
     }
 
+    mi->ev_arg.type = EVENT_ARG_MULTI_INSTANCE;
+    mi->ev_arg.u.mi = mi;
+
     perf_pop();
     gc_free(&gc);
     return mi;
src/openvpn/multi.h +6 -0
index 7167639..1b99ef7 100644
@@ -102,6 +102,12 @@
     struct schedule_entry se;  /* this must be the first element of the structure,
                                 * We cast between this and schedule_entry so the
                                 * beginning of the struct must be identical */
+
+    struct event_arg ev_arg;   /**< this struct will store a pointer to either mi or
+                                * link_socket, depending on the event type, to keep
+                                * it accessible it's placed within the same struct
+                                * it points to. */
+
     struct gc_arena gc;
     bool halt;
     int refcount;
src/openvpn/socket.c +2 -0
index 7b1e603..cf04090 100644
@@ -1830,6 +1830,8 @@
     ALLOC_OBJ_CLEAR(sock, struct link_socket);
     sock->sd = SOCKET_UNDEFINED;
     sock->ctrl_sd = SOCKET_UNDEFINED;
+    sock->ev_arg.type = EVENT_ARG_LINK_SOCKET;
+
     return sock;
 }
 
src/openvpn/socket.h +5 -0
index 2e583af..c152ab0 100644
@@ -178,6 +178,11 @@
 {
     struct link_socket_info info;
 
+    struct event_arg ev_arg;   /**< this struct will store a pointer to either mi or
+                                * link_socket, depending on the event type, to keep
+                                * it accessible it's placed within the same struct
+                                * it points to. */
+
     socket_descriptor_t sd;
     socket_descriptor_t ctrl_sd; /* only used for UDP over Socks */
 

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/757?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Icd7f6a2ad350cdc2312b3e80fa0dbdd7e4311d2e
Gerrit-Change-Number: 757
Gerrit-PatchSet: 4
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-CC: ordex <[email protected]...>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newpatchset

#13 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, plaisthos.

its_Giaan has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/757?usp=email )

Change subject: event/multi: add event_arg object to make event handling more generic
......................................................................

Patch Set 4:

(3 comments)

File src/openvpn/mtcp.c:

http://gerrit.openvpn.net/c/openvpn/+/757/comment/bd54e635_fd461c9e :
PS3, Line 694: *

Quoted 1 line

any reason to define this before the if?

Done

File src/openvpn/multi.h:

http://gerrit.openvpn.net/c/openvpn/+/757/comment/c4f2855b_6b8fd60b :
PS3, Line 106: this

Quoted 1 line

Forgot "<" so this comment applies to gc

Done

File src/openvpn/socket.h:

http://gerrit.openvpn.net/c/openvpn/+/757/comment/726a0fd2_373da8b1 :
PS3, Line 181: struct event_arg ev_arg; /** this struct will store a pointer to either mi or

Quoted 1 line

Forgot "<" so this comment applies to sd

Done

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/757?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Icd7f6a2ad350cdc2312b3e80fa0dbdd7e4311d2e
Gerrit-Change-Number: 757
Gerrit-PatchSet: 4
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-CC: ordex <[email protected]...>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Fri, 11 Oct 2024 14:08:34 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: flichtenheld <[email protected]...>
Gerrit-MessageType: comment

#14 lore raw
In reply to a message not in the archive

Attention is currently required from: its_Giaan, plaisthos.

flichtenheld has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/757?usp=email )

Change subject: event/multi: add event_arg object to make event handling more generic
......................................................................

Patch Set 4: Code-Review+2

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/757?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Icd7f6a2ad350cdc2312b3e80fa0dbdd7e4311d2e
Gerrit-Change-Number: 757
Gerrit-PatchSet: 4
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-CC: ordex <[email protected]...>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Comment-Date: Fri, 11 Oct 2024 15:29:16 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment

#15 lore raw

PATCH v4 1/1 event/multi: add event_arg object to make event handling more generic

In reply to a message not in the archive

From: Antonio Quartulli <[email protected]...>

In order to prepare the event handling code to deal with multiple listening sockets, we have to make sure that it is possible to distinguish which of these sockets have been poked by an incoming connection request.

To achieve that, this patch changes the object being passed as event handler argument, from a "partly integer-evaluated variable" to a full struct with a proper type attribute.

This struct will allow the code to carry around the particular listening socket where the connection is being established.

This change affects the TCP server code path only as UDP servers use only one socket to handle all clients.

Change-Id Icd7f6a2ad350cdc2312b3e80fa0dbdd7e4311d2e

---

This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master.

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/757
This mail reflects revision 4 of this Change.

Acked-by according to Gerrit (reflected above):
Frank Lichtenheld <[email protected]...>

src/openvpn/event.h +14 -0
index 856551a..844ea7b 100644
@@ -126,6 +126,20 @@
     struct event_set_functions func;
 };
 
+typedef enum {
+    EVENT_ARG_MULTI_INSTANCE = 0,
+    EVENT_ARG_LINK_SOCKET,
+} event_arg_t;
+
+/* generic event argument object to pass to event_ctl() */
+struct event_arg
+{
+    event_arg_t type;
+    union {
+        struct multi_instance *mi; /* if type = EVENT_ARG_MULTI_INSTANCE */
+    } u;
+};
+
 /*
  * maxevents on input:  desired max number of event_t descriptors
  *                      simultaneously set with event_ctl
src/openvpn/mtcp.c +38 -28

105 lines not on this page · raw message

src/openvpn/multi.c +3 -0
index 0509911..45b3cfa 100644
@@ -823,6 +823,9 @@
         goto err;
     }
 
+    mi->ev_arg.type = EVENT_ARG_MULTI_INSTANCE;
+    mi->ev_arg.u.mi = mi;
+
     perf_pop();
     gc_free(&gc);
     return mi;
src/openvpn/multi.h +6 -0
index 7167639..1b99ef7 100644
@@ -102,6 +102,12 @@
     struct schedule_entry se;  /* this must be the first element of the structure,
                                 * We cast between this and schedule_entry so the
                                 * beginning of the struct must be identical */
+
+    struct event_arg ev_arg;   /**< this struct will store a pointer to either mi or
+                                * link_socket, depending on the event type, to keep
+                                * it accessible it's placed within the same struct
+                                * it points to. */
+
     struct gc_arena gc;
     bool halt;
     int refcount;
src/openvpn/socket.c +2 -0
index 7b1e603..cf04090 100644
@@ -1830,6 +1830,8 @@
     ALLOC_OBJ_CLEAR(sock, struct link_socket);
     sock->sd = SOCKET_UNDEFINED;
     sock->ctrl_sd = SOCKET_UNDEFINED;
+    sock->ev_arg.type = EVENT_ARG_LINK_SOCKET;
+
     return sock;
 }
 
src/openvpn/socket.h +5 -0
index 2e583af..c152ab0 100644
@@ -178,6 +178,11 @@
 {
     struct link_socket_info info;
 
+    struct event_arg ev_arg;   /**< this struct will store a pointer to either mi or
+                                * link_socket, depending on the event type, to keep
+                                * it accessible it's placed within the same struct
+                                * it points to. */
+
     socket_descriptor_t sd;
     socket_descriptor_t ctrl_sd; /* only used for UDP over Socks */
 
#16 lore raw

PATCH v4 1/1 event/multi: add event_arg object to make event handling more generic

From: Antonio Quartulli <[email protected]...>

In order to prepare the event handling code to deal with multiple listening sockets, we have to make sure that it is possible to distinguish which of these sockets have been poked by an incoming connection request.

To achieve that, this patch changes the object being passed as event handler argument, from a "partly integer-evaluated variable" to a full struct with a proper type attribute.

This struct will allow the code to carry around the particular listening socket where the connection is being established.

This change affects the TCP server code path only as UDP servers use only one socket to handle all clients.

Change-Id Icd7f6a2ad350cdc2312b3e80fa0dbdd7e4311d2e

---

This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master.

Manually added Signed-off-by for Giaan.

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/757
This mail reflects revision 4 of this Change.

Acked-by according to Gerrit (reflected above):
Frank Lichtenheld <[email protected]...>

src/openvpn/event.h +14 -0
index 856551a..844ea7b 100644
@@ -126,6 +126,20 @@
     struct event_set_functions func;
 };
 
+typedef enum {
+    EVENT_ARG_MULTI_INSTANCE = 0,
+    EVENT_ARG_LINK_SOCKET,
+} event_arg_t;
+
+/* generic event argument object to pass to event_ctl() */
+struct event_arg
+{
+    event_arg_t type;
+    union {
+        struct multi_instance *mi; /* if type = EVENT_ARG_MULTI_INSTANCE */
+    } u;
+};
+
 /*
  * maxevents on input:  desired max number of event_t descriptors
  *                      simultaneously set with event_ctl
src/openvpn/mtcp.c +38 -28

105 lines not on this page · raw message

src/openvpn/multi.c +3 -0
index 0509911..45b3cfa 100644
@@ -823,6 +823,9 @@
         goto err;
     }
 
+    mi->ev_arg.type = EVENT_ARG_MULTI_INSTANCE;
+    mi->ev_arg.u.mi = mi;
+
     perf_pop();
     gc_free(&gc);
     return mi;
src/openvpn/multi.h +6 -0
index 7167639..1b99ef7 100644
@@ -102,6 +102,12 @@
     struct schedule_entry se;  /* this must be the first element of the structure,
                                 * We cast between this and schedule_entry so the
                                 * beginning of the struct must be identical */
+
+    struct event_arg ev_arg;   /**< this struct will store a pointer to either mi or
+                                * link_socket, depending on the event type, to keep
+                                * it accessible it's placed within the same struct
+                                * it points to. */
+
     struct gc_arena gc;
     bool halt;
     int refcount;
src/openvpn/socket.c +2 -0
index 7b1e603..cf04090 100644
@@ -1830,6 +1830,8 @@
     ALLOC_OBJ_CLEAR(sock, struct link_socket);
     sock->sd = SOCKET_UNDEFINED;
     sock->ctrl_sd = SOCKET_UNDEFINED;
+    sock->ev_arg.type = EVENT_ARG_LINK_SOCKET;
+
     return sock;
 }
 
src/openvpn/socket.h +5 -0
index 2e583af..c152ab0 100644
@@ -178,6 +178,11 @@
 {
     struct link_socket_info info;
 
+    struct event_arg ev_arg;   /**< this struct will store a pointer to either mi or
+                                * link_socket, depending on the event type, to keep
+                                * it accessible it's placed within the same struct
+                                * it points to. */
+
     socket_descriptor_t sd;
     socket_descriptor_t ctrl_sd; /* only used for UDP over Socks */
 
#17 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, its_Giaan, ordex, plaisthos.

Hello flichtenheld, ordex, plaisthos,

I'd like you to reexamine a change. Please visit

    http://gerrit.openvpn.net/c/openvpn/+/757?usp=email

to look at the new patch set (#5).

The following approvals got outdated and were removed:
Code-Review+2 by flichtenheld

The change is no longer submittable: Code-Review and checks~ChecksSubmitRule are unsatisfied now.

Change subject: event/multi: add event_arg object to make event handling more generic
......................................................................

event/multi: add event_arg object to make event handling more generic

In order to prepare the event handling code to deal with multiple listening sockets, we have to make sure that it is possible to distinguish which of these sockets have been poked by an incoming connection request.

To achieve that, this patch changes the object being passed as event handler argument, from a "partly integer-evaluated variable" to a full struct with a proper type attribute.

This struct will allow the code to carry around the particular listening socket where the connection is being established.

This change affects the TCP server code path only as UDP servers use only one socket to handle all clients.

Change-Id Icd7f6a2ad350cdc2312b3e80fa0dbdd7e4311d2e

---
M src/openvpn/event.h
M src/openvpn/mtcp.c
M src/openvpn/multi.c
M src/openvpn/multi.h
M src/openvpn/socket.c
M src/openvpn/socket.h

6 files changed, 68 insertions(+), 28 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/57/757/5

src/openvpn/event.h +14 -0
index 856551a..844ea7b 100644
@@ -126,6 +126,20 @@
     struct event_set_functions func;
 };
 
+typedef enum {
+    EVENT_ARG_MULTI_INSTANCE = 0,
+    EVENT_ARG_LINK_SOCKET,
+} event_arg_t;
+
+/* generic event argument object to pass to event_ctl() */
+struct event_arg
+{
+    event_arg_t type;
+    union {
+        struct multi_instance *mi; /* if type = EVENT_ARG_MULTI_INSTANCE */
+    } u;
+};
+
 /*
  * maxevents on input:  desired max number of event_t descriptors
  *                      simultaneously set with event_ctl
src/openvpn/mtcp.c +38 -28

105 lines not on this page · raw message

src/openvpn/multi.c +3 -0
index 0509911..45b3cfa 100644
@@ -823,6 +823,9 @@
         goto err;
     }
 
+    mi->ev_arg.type = EVENT_ARG_MULTI_INSTANCE;
+    mi->ev_arg.u.mi = mi;
+
     perf_pop();
     gc_free(&gc);
     return mi;
src/openvpn/multi.h +6 -0
index 7167639..1b99ef7 100644
@@ -102,6 +102,12 @@
     struct schedule_entry se;  /* this must be the first element of the structure,
                                 * We cast between this and schedule_entry so the
                                 * beginning of the struct must be identical */
+
+    struct event_arg ev_arg;   /**< this struct will store a pointer to either mi or
+                                * link_socket, depending on the event type, to keep
+                                * it accessible it's placed within the same struct
+                                * it points to. */
+
     struct gc_arena gc;
     bool halt;
     int refcount;
src/openvpn/socket.c +2 -0
index 7b1e603..cf04090 100644
@@ -1830,6 +1830,8 @@
     ALLOC_OBJ_CLEAR(sock, struct link_socket);
     sock->sd = SOCKET_UNDEFINED;
     sock->ctrl_sd = SOCKET_UNDEFINED;
+    sock->ev_arg.type = EVENT_ARG_LINK_SOCKET;
+
     return sock;
 }
 
src/openvpn/socket.h +5 -0
index 2e583af..c152ab0 100644
@@ -178,6 +178,11 @@
 {
     struct link_socket_info info;
 
+    struct event_arg ev_arg;   /**< this struct will store a pointer to either mi or
+                                * link_socket, depending on the event type, to keep
+                                * it accessible it's placed within the same struct
+                                * it points to. */
+
     socket_descriptor_t sd;
     socket_descriptor_t ctrl_sd; /* only used for UDP over Socks */
 

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/757?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Icd7f6a2ad350cdc2312b3e80fa0dbdd7e4311d2e
Gerrit-Change-Number: 757
Gerrit-PatchSet: 5
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: ordex <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-MessageType: newpatchset

#18 lore raw
In reply to a message not in the archive

Attention is currently required from: its_Giaan, ordex, plaisthos.

flichtenheld has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/757?usp=email )

Change subject: event/multi: add event_arg object to make event handling more generic
......................................................................

Patch Set 5: Code-Review+2

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/757?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Icd7f6a2ad350cdc2312b3e80fa0dbdd7e4311d2e
Gerrit-Change-Number: 757
Gerrit-PatchSet: 5
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: ordex <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-Comment-Date: Thu, 17 Oct 2024 15:37:16 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment

#19 lore raw

PATCH v5 1/1 event/multi: add event_arg object to make event handling more generic

In reply to a message not in the archive

From: Antonio Quartulli <[email protected]...>

In order to prepare the event handling code to deal with multiple listening sockets, we have to make sure that it is possible to distinguish which of these sockets have been poked by an incoming connection request.

To achieve that, this patch changes the object being passed as event handler argument, from a "partly integer-evaluated variable" to a full struct with a proper type attribute.

This struct will allow the code to carry around the particular listening socket where the connection is being established.

This change affects the TCP server code path only as UDP servers use only one socket to handle all clients.

Change-Id Icd7f6a2ad350cdc2312b3e80fa0dbdd7e4311d2e

---

This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master.

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/757
This mail reflects revision 5 of this Change.

Acked-by according to Gerrit (reflected above):
Frank Lichtenheld <[email protected]...>

src/openvpn/event.h +14 -0
index 856551a..844ea7b 100644
@@ -126,6 +126,20 @@
     struct event_set_functions func;
 };
 
+typedef enum {
+    EVENT_ARG_MULTI_INSTANCE = 0,
+    EVENT_ARG_LINK_SOCKET,
+} event_arg_t;
+
+/* generic event argument object to pass to event_ctl() */
+struct event_arg
+{
+    event_arg_t type;
+    union {
+        struct multi_instance *mi; /* if type = EVENT_ARG_MULTI_INSTANCE */
+    } u;
+};
+
 /*
  * maxevents on input:  desired max number of event_t descriptors
  *                      simultaneously set with event_ctl
src/openvpn/mtcp.c +38 -28

105 lines not on this page · raw message

src/openvpn/multi.c +3 -0
index 0509911..45b3cfa 100644
@@ -823,6 +823,9 @@
         goto err;
     }
 
+    mi->ev_arg.type = EVENT_ARG_MULTI_INSTANCE;
+    mi->ev_arg.u.mi = mi;
+
     perf_pop();
     gc_free(&gc);
     return mi;
src/openvpn/multi.h +6 -0
index 7167639..1b99ef7 100644
@@ -102,6 +102,12 @@
     struct schedule_entry se;  /* this must be the first element of the structure,
                                 * We cast between this and schedule_entry so the
                                 * beginning of the struct must be identical */
+
+    struct event_arg ev_arg;   /**< this struct will store a pointer to either mi or
+                                * link_socket, depending on the event type, to keep
+                                * it accessible it's placed within the same struct
+                                * it points to. */
+
     struct gc_arena gc;
     bool halt;
     int refcount;
src/openvpn/socket.c +2 -0
index 7b1e603..cf04090 100644
@@ -1830,6 +1830,8 @@
     ALLOC_OBJ_CLEAR(sock, struct link_socket);
     sock->sd = SOCKET_UNDEFINED;
     sock->ctrl_sd = SOCKET_UNDEFINED;
+    sock->ev_arg.type = EVENT_ARG_LINK_SOCKET;
+
     return sock;
 }
 
src/openvpn/socket.h +5 -0
index 2e583af..c152ab0 100644
@@ -178,6 +178,11 @@
 {
     struct link_socket_info info;
 
+    struct event_arg ev_arg;   /**< this struct will store a pointer to either mi or
+                                * link_socket, depending on the event type, to keep
+                                * it accessible it's placed within the same struct
+                                * it points to. */
+
     socket_descriptor_t sd;
     socket_descriptor_t ctrl_sd; /* only used for UDP over Socks */
 
#20 lore raw

[Openvpn-devel] [PATCH applied] Re: event/multi: add event_arg object to make event handling more generic

I've lightly tested this on the server testbed (it has TCP listeners, and extensive t_client tests - everyhing is fine), and also stared a bit at the code (which seems reasonable, and Frank has more extensibly reviewed it already).

There's some questions I do not understand (like, why not store the ev_arg in the event structure? why pass the ev_arg to socket_set_listen_persistent() when it is passed the socket itself already?) but I guess there's good reasons for it...

Your patch has been applied to the master branch.

commit cd8e25a6e9a0fc3687cf8b9df460885db2aee566 (master)

Author: Antonio Quartulli
Date:   Wed Oct 23 10:08:52 2024 +0200
     event/multi: add event_arg object to make event handling more generic

     Signed-off-by: Antonio Quartulli <[email protected]...>
     Signed-off-by: Gianmarco De Gregori <[email protected]...>
     Acked-by: Frank Lichtenheld <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg29602.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#21 lore raw

Re: [Openvpn-devel] [PATCH applied] Re: event/multi: add event_arg object to make event handling more generic

Hi,

Quoted 10 lines · Gert Doering

I've lightly tested this on the server testbed (it has TCP listeners, and extensive t_client tests - everyhing is fine), and also stared a bit at the code (which seems reasonable, and Frank has more extensibly reviewed it already).

Your patch has been applied to the master branch.

commit cd8e25a6e9a0fc3687cf8b9df460885db2aee566 (master)

Author: Antonio Quartulli
Date:   Wed Oct 23 10:08:52 2024 +0200

Unfortunately, this breaks Windows building, which our "pre-GH push" test infra does not cover yet (and I assumed this to be sufficiently OS independent... so, don't). Patch incoming...

gert

Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you 
 feed honest figures into a computer, honest figures come out. Never doubted 
 it myself till I met a computer with a sense of humor."
                             Robert A. Heinlein, The Moon is a Harsh Mistress

Gert Doering - Munich, Germany                             [email protected]...
#22 lore raw
In reply to a message not in the archive

cron2 has uploaded a new patch set (#6) to the change originally created by its_Giaan. ( http://gerrit.openvpn.net/c/openvpn/+/757?usp=email )

The following approvals got outdated and were removed:
Code-Review+2 by flichtenheld

Change subject: event/multi: add event_arg object to make event handling more generic
......................................................................

event/multi: add event_arg object to make event handling more generic

In order to prepare the event handling code to deal with multiple listening sockets, we have to make sure that it is possible to distinguish which of these sockets have been poked by an incoming connection request.

To achieve that, this patch changes the object being passed as event handler argument, from a "partly integer-evaluated variable" to a full struct with a proper type attribute.

This struct will allow the code to carry around the particular listening socket where the connection is being established.

This change affects the TCP server code path only as UDP servers use only one socket to handle all clients.

Change-Id Icd7f6a2ad350cdc2312b3e80fa0dbdd7e4311d2e

Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg29602.html

---
M src/openvpn/event.h
M src/openvpn/mtcp.c
M src/openvpn/multi.c
M src/openvpn/multi.h
M src/openvpn/socket.c
M src/openvpn/socket.h

6 files changed, 68 insertions(+), 28 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/57/757/6

src/openvpn/event.h +14 -0
index 856551a..844ea7b 100644
@@ -126,6 +126,20 @@
     struct event_set_functions func;
 };
 
+typedef enum {
+    EVENT_ARG_MULTI_INSTANCE = 0,
+    EVENT_ARG_LINK_SOCKET,
+} event_arg_t;
+
+/* generic event argument object to pass to event_ctl() */
+struct event_arg
+{
+    event_arg_t type;
+    union {
+        struct multi_instance *mi; /* if type = EVENT_ARG_MULTI_INSTANCE */
+    } u;
+};
+
 /*
  * maxevents on input:  desired max number of event_t descriptors
  *                      simultaneously set with event_ctl
src/openvpn/mtcp.c +38 -28

105 lines not on this page · raw message

src/openvpn/multi.c +3 -0
index 0509911..45b3cfa 100644
@@ -823,6 +823,9 @@
         goto err;
     }
 
+    mi->ev_arg.type = EVENT_ARG_MULTI_INSTANCE;
+    mi->ev_arg.u.mi = mi;
+
     perf_pop();
     gc_free(&gc);
     return mi;
src/openvpn/multi.h +6 -0
index 7167639..1b99ef7 100644
@@ -102,6 +102,12 @@
     struct schedule_entry se;  /* this must be the first element of the structure,
                                 * We cast between this and schedule_entry so the
                                 * beginning of the struct must be identical */
+
+    struct event_arg ev_arg;   /**< this struct will store a pointer to either mi or
+                                * link_socket, depending on the event type, to keep
+                                * it accessible it's placed within the same struct
+                                * it points to. */
+
     struct gc_arena gc;
     bool halt;
     int refcount;
src/openvpn/socket.c +2 -0
index 7b1e603..cf04090 100644
@@ -1830,6 +1830,8 @@
     ALLOC_OBJ_CLEAR(sock, struct link_socket);
     sock->sd = SOCKET_UNDEFINED;
     sock->ctrl_sd = SOCKET_UNDEFINED;
+    sock->ev_arg.type = EVENT_ARG_LINK_SOCKET;
+
     return sock;
 }
 
src/openvpn/socket.h +5 -0
index 04eb8a4..27caab4 100644
@@ -178,6 +178,11 @@
 {
     struct link_socket_info info;
 
+    struct event_arg ev_arg;   /**< this struct will store a pointer to either mi or
+                                * link_socket, depending on the event type, to keep
+                                * it accessible it's placed within the same struct
+                                * it points to. */
+
     socket_descriptor_t sd;
     socket_descriptor_t ctrl_sd; /* only used for UDP over Socks */
 

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/757?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Icd7f6a2ad350cdc2312b3e80fa0dbdd7e4311d2e
Gerrit-Change-Number: 757
Gerrit-PatchSet: 6
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-CC: ordex <[email protected]...>
Gerrit-MessageType: newpatchset

#23 lore raw
In reply to a message not in the archive

cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/757?usp=email )

Change subject: event/multi: add event_arg object to make event handling more generic
......................................................................

event/multi: add event_arg object to make event handling more generic

In order to prepare the event handling code to deal with multiple listening sockets, we have to make sure that it is possible to distinguish which of these sockets have been poked by an incoming connection request.

To achieve that, this patch changes the object being passed as event handler argument, from a "partly integer-evaluated variable" to a full struct with a proper type attribute.

This struct will allow the code to carry around the particular listening socket where the connection is being established.

This change affects the TCP server code path only as UDP servers use only one socket to handle all clients.

Change-Id Icd7f6a2ad350cdc2312b3e80fa0dbdd7e4311d2e

Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg29602.html

---
M src/openvpn/event.h
M src/openvpn/mtcp.c
M src/openvpn/multi.c
M src/openvpn/multi.h
M src/openvpn/socket.c
M src/openvpn/socket.h

6 files changed, 68 insertions(+), 28 deletions(-)
src/openvpn/event.h +14 -0
index 856551a..844ea7b 100644
@@ -126,6 +126,20 @@
     struct event_set_functions func;
 };
 
+typedef enum {
+    EVENT_ARG_MULTI_INSTANCE = 0,
+    EVENT_ARG_LINK_SOCKET,
+} event_arg_t;
+
+/* generic event argument object to pass to event_ctl() */
+struct event_arg
+{
+    event_arg_t type;
+    union {
+        struct multi_instance *mi; /* if type = EVENT_ARG_MULTI_INSTANCE */
+    } u;
+};
+
 /*
  * maxevents on input:  desired max number of event_t descriptors
  *                      simultaneously set with event_ctl
src/openvpn/mtcp.c +38 -28

105 lines not on this page · raw message

src/openvpn/multi.c +3 -0
index 0509911..45b3cfa 100644
@@ -823,6 +823,9 @@
         goto err;
     }
 
+    mi->ev_arg.type = EVENT_ARG_MULTI_INSTANCE;
+    mi->ev_arg.u.mi = mi;
+
     perf_pop();
     gc_free(&gc);
     return mi;
src/openvpn/multi.h +6 -0
index 7167639..1b99ef7 100644
@@ -102,6 +102,12 @@
     struct schedule_entry se;  /* this must be the first element of the structure,
                                 * We cast between this and schedule_entry so the
                                 * beginning of the struct must be identical */
+
+    struct event_arg ev_arg;   /**< this struct will store a pointer to either mi or
+                                * link_socket, depending on the event type, to keep
+                                * it accessible it's placed within the same struct
+                                * it points to. */
+
     struct gc_arena gc;
     bool halt;
     int refcount;
src/openvpn/socket.c +2 -0
index 7b1e603..cf04090 100644
@@ -1830,6 +1830,8 @@
     ALLOC_OBJ_CLEAR(sock, struct link_socket);
     sock->sd = SOCKET_UNDEFINED;
     sock->ctrl_sd = SOCKET_UNDEFINED;
+    sock->ev_arg.type = EVENT_ARG_LINK_SOCKET;
+
     return sock;
 }
 
src/openvpn/socket.h +5 -0
index 04eb8a4..27caab4 100644
@@ -178,6 +178,11 @@
 {
     struct link_socket_info info;
 
+    struct event_arg ev_arg;   /**< this struct will store a pointer to either mi or
+                                * link_socket, depending on the event type, to keep
+                                * it accessible it's placed within the same struct
+                                * it points to. */
+
     socket_descriptor_t sd;
     socket_descriptor_t ctrl_sd; /* only used for UDP over Socks */
 

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/757?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Icd7f6a2ad350cdc2312b3e80fa0dbdd7e4311d2e
Gerrit-Change-Number: 757
Gerrit-PatchSet: 6
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-CC: ordex <[email protected]...>
Gerrit-MessageType: merged